package class10;

import java.util.PriorityQueue;

/**
 * @author zhangchaoliang
 * create 2022
 */
public class lessMoney {

    public static int lessMoney(int[] arr){
        PriorityQueue<Integer> pQ = new PriorityQueue<>();
        for (int i=0;i<arr.length;i++){
            pQ.add(arr[i]);
        }
        int sum = 0;
        int cur = 0;
        while (pQ.size()>1){
            cur = pQ.poll() + pQ.poll();
            sum += cur;
            pQ.add(cur);
        }
        return sum;
    }
}
